﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.ServiceModel;
using System.ServiceModel.Web;
using Amazon.Route53.DataContracts;

namespace Amazon.Route53
{
    public partial class AmazonRoute53 : IAmazonRoute53
    {
        private System.ServiceModel.Web.WebChannelFactory<IAmazonRoute53> Channel = null;


        public AmazonRoute53(string awsAccessKey, string awsSecretAccessKey)
        {
            System.ServiceModel.WebHttpBinding Binding = new System.ServiceModel.WebHttpBinding();
            Binding.Security.Mode = System.ServiceModel.WebHttpSecurityMode.Transport;
            Binding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.None;

            Channel = new System.ServiceModel.Web.WebChannelFactory<IAmazonRoute53>(Binding, new System.Uri(Constants.TargetUri));
            Channel.Endpoint.Behaviors.Add(new Amazon.Route53.WCFExtension.CustomWebHttpBehavior(awsAccessKey, awsSecretAccessKey));
        }

        #region IAmazonRoute53 Members

        #region List Hosted Zones

        public HostedZonesList ListHostedZones()
        {
            try
            {
                return Channel.CreateChannel().ListHostedZones();
            }
            catch (System.ServiceModel.ProtocolException PE)
            {
                throw PE.PrepareException();
            }
        }

        public HostedZonesList ListHostedZones(string marker, int maxitems)
        {
            try
            {
                return Channel.CreateChannel().ListHostedZones(marker, maxitems);
            }
            catch (System.ServiceModel.ProtocolException PE)
            {
                throw PE.PrepareException();
            }
        }

        public HostedZonesList ListHostedZones(int maxitems)
        {
            try
            {
                return Channel.CreateChannel().ListHostedZones(maxitems);
            }
            catch (System.ServiceModel.ProtocolException PE)
            {
                throw PE.PrepareException();
            }
        }

        public HostedZoneDetail GetHostedZoneById(String HostedZoneId)
        {
            try
            {
                return Channel.CreateChannel().GetHostedZoneById(HostedZoneId);
            }
            catch (System.ServiceModel.ProtocolException PE)
            {
                throw PE.PrepareException();
            }
        }

        #endregion

        #region Hosted Zone CRUD Operations

        public CreateHostedZoneResponse CreateHostedZone(HostedZoneRequest Request)
        {
            try
            {
                return Channel.CreateChannel().CreateHostedZone(Request);
            }
            catch (System.ServiceModel.ProtocolException PE)
            {
                throw PE.PrepareException();
            }
        }

        public DeletedHostedZone DeleteHostedZone(String HostedZoneId)
        {
            try
            {
                return Channel.CreateChannel().DeleteHostedZone(HostedZoneId);
            }
            catch (System.ServiceModel.ProtocolException PE)
            {
                throw PE.PrepareException();
            }
        }

        #endregion

        #region Resource Record Sets CRUD Operations

        public ChangeResourceRecordSetsResponse ChangeResourceRecordSets(String HostedZoneId, ResourceRecordSetsChangeRequest Request)
        {
            try
            {
                return Channel.CreateChannel().ChangeResourceRecordSets(HostedZoneId, Request);
            }
            catch (ProtocolException pe)
            {
                throw pe.PrepareException();
            }
        }

        public GetChangeResponse GetChange(String ChangeId)
        {
            try
            {
                return Channel.CreateChannel().GetChange(ChangeId);
            }
            catch (ProtocolException PE)
            {
                throw PE.PrepareException();
            }
        }

        #endregion

        #region List Resource Record Sets

        public ListResourceRecordSetsResponse ListResourceRecordSets(String HostedZoneId)
        {
            try
            {
                return Channel.CreateChannel().ListResourceRecordSets(HostedZoneId);
            }
            catch (ProtocolException PE)
            {
                throw PE.PrepareException();
            }
        }

        public ListResourceRecordSetsResponse ListResourceRecordSets(String HostedZoneId, string name)
        {
            try
            {
                return Channel.CreateChannel().ListResourceRecordSets(HostedZoneId, name);
            }
            catch (ProtocolException PE)
            {
                throw PE.PrepareException();
            }
        }

        public ListResourceRecordSetsResponse ListResourceRecordSets(String HostedZoneId, int maxitems)
        {
            try
            {
                return Channel.CreateChannel().ListResourceRecordSets(HostedZoneId, maxitems);
            }
            catch (ProtocolException PE)
            {
                throw PE.PrepareException();
            }
        }

        public ListResourceRecordSetsResponse ListResourceRecordSets(String HostedZoneId, DomainNameType dnType, string name)
        {
            try
            {
                return Channel.CreateChannel().ListResourceRecordSets(HostedZoneId, dnType, name);
            }
            catch (ProtocolException PE)
            {
                throw PE.PrepareException();
            }
        }


        public ListResourceRecordSetsResponse ListResourceRecordSets(String HostedZoneId, string name, int maxitems)
        {
            try
            {
                return Channel.CreateChannel().ListResourceRecordSets(HostedZoneId, name, maxitems);
            }
            catch (ProtocolException PE)
            {
                throw PE.PrepareException();
            }
        }

        public ListResourceRecordSetsResponse ListResourceRecordSets(String HostedZoneId, DomainNameType dnType, string name, int maxitems)
        {
            try
            {
                return Channel.CreateChannel().ListResourceRecordSets(HostedZoneId, dnType, name, maxitems);
            }
            catch (ProtocolException PE)
            {
                throw PE.PrepareException();
            }
        }

        #endregion

        #endregion
    }
}
